/**
 * 
 */
package mv.releaser.model;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Observable;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;

/**
 * @author kal
 *
 */
public class CRC extends Observable{
	private File fin;

	public CRC(File fin) {
		this.fin = fin;
	}

	public long getCRC() throws IOException {
		FileInputStream f = new FileInputStream(fin);
		CheckedInputStream cis = new CheckedInputStream(f, new CRC32());

		// Computer CRC32 checksum
		byte[] buf = new byte[128];
		int value = 0; 
		while(cis.read(buf) >= 0) {
			setChanged();
			notifyObservers(value += 128);
		}
		
		f.close();
		cis.close();
		
		return cis.getChecksum().getValue();
		
	}

	public long getFileSize() {
		return fin.length();
	}
	
	
}
